package com.buercc.boot.utils.redis.impl;

import com.buercc.boot.utils.redis.RedisDBHelper;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import java.util.concurrent.TimeUnit;

public class RedisDBHelperImpl implements RedisDBHelper {

    private StringRedisTemplate redisTemplate;
    private ValueOperations operations;

    public RedisDBHelperImpl(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
        this.operations = redisTemplate.opsForValue();
    }

    @Override
    public void put(String key, Object value) {
        operations.set(key, value);
    }

    @Override
    public void put(String key, Object value, Long expireTime) {
        operations.set(key, value, expireTime, TimeUnit.MINUTES);
    }

    @Override
    public Object get(String key) {
        return operations.get(key);
    }

    @Override
    public boolean hasKey(String key) {
        return redisTemplate.hasKey(key);
    }

    @Override
    public void remove(String key) {
        redisTemplate.delete(key);
    }
}
